<template>
  <a-drawer
    :title="title"
    :width="width"
    placement="right"
    :closable="false"
    @close="close"
    :visible="visible">
  
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">

        <a-form-item label="姓名" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['name']" placeholder="请输入姓名"></a-input>
        </a-form-item>
        <a-form-item label="单位" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['danwei']" placeholder="请输入单位"></a-input>
        </a-form-item>
        <a-form-item label="入职时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['ruzhidt']" placeholder="请输入入职时间"></a-input>
        </a-form-item>
        <a-form-item label="原部门" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['oldbm']" placeholder="请输入原部门"></a-input>
        </a-form-item>
        <a-form-item label="原职务" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['oldzw']" placeholder="请输入原职务"></a-input>
        </a-form-item>
        <a-form-item label="原主要工作内容" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['oldmain']" placeholder="请输入原主要工作内容"></a-input>
        </a-form-item>
        <a-form-item label="原基本工资" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['oldbasic']" placeholder="请输入原基本工资"></a-input>
        </a-form-item>
        <a-form-item label="新部门" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['newbm']" placeholder="请输入新部门"></a-input>
        </a-form-item>
        <a-form-item label="新岗位" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['newgw']" placeholder="请输入新岗位"></a-input>
        </a-form-item>
        <a-form-item label="新主要工作内容" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['newmain']" placeholder="请输入新主要工作内容"></a-input>
        </a-form-item>
        <a-form-item label="新基本工资" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['newjbgz']" placeholder="请输入新基本工资"></a-input>
        </a-form-item>
        <a-form-item label="交通补贴" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['jiaotongbutie']" placeholder="请输入交通补贴"></a-input>
        </a-form-item>
        <a-form-item label="通讯费" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['tongxunfei']" placeholder="请输入通讯费"></a-input>
        </a-form-item>
        <a-form-item label="生活补贴" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['shbt']" placeholder="请输入生活补贴"></a-input>
        </a-form-item>
        <a-form-item label="房补" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['fangbu']" placeholder="请输入房补"></a-input>
        </a-form-item>
        <a-form-item label="工龄津贴" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['gljt']" placeholder="请输入工龄津贴"></a-input>
        </a-form-item>
        <a-form-item label="岗位工资" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['gwgz']" placeholder="请输入岗位工资"></a-input>
        </a-form-item>
        <a-form-item label="浮动工资" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['fdgz']" placeholder="请输入浮动工资"></a-input>
        </a-form-item>
        <a-form-item label="养老保险代缴" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['yldaijiao']" placeholder="请输入养老保险代缴"></a-input>
        </a-form-item>
        <a-form-item label="养老保险代缴金额" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['yldaijiaoje']" placeholder="请输入养老保险代缴金额"></a-input>
        </a-form-item>
        <a-form-item label="失业保险代缴" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['shiyedaijiao']" placeholder="请输入失业保险代缴"></a-input>
        </a-form-item>
        <a-form-item label="失业保险代缴金额" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['shiyedaijiaoje']" placeholder="请输入失业保险代缴金额"></a-input>
        </a-form-item>
        <a-form-item label="医疗保险代缴" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['yiliaodaijiao']" placeholder="请输入医疗保险代缴"></a-input>
        </a-form-item>
        <a-form-item label="医疗保险代缴金额" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['yiliaodaijiaoje']" placeholder="请输入医疗保险代缴金额"></a-input>
        </a-form-item>
        <a-form-item label="变更原因" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['bgyuanyin']" placeholder="请输入变更原因"></a-input>
        </a-form-item>
        <a-form-item label="生效日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['sxdt']" placeholder="请输入生效日期"></a-input>
        </a-form-item>
        <a-form-item label="创建人" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['createBy']" placeholder="请输入创建人"></a-input>
        </a-form-item>
        <a-form-item label="创建日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择创建日期" v-decorator="['createTime']" :trigger-change="true" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="更新人" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['updateBy']" placeholder="请输入更新人"></a-input>
        </a-form-item>
        <a-form-item label="更新日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择更新日期" v-decorator="['updateTime']" :trigger-change="true" style="width: 100%"/>
        </a-form-item>
        
      </a-form>
    </a-spin>
    <a-button type="primary" @click="handleOk">确定</a-button>
    <a-button type="primary" @click="handleCancel">取消</a-button>
  </a-drawer>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import { validateDuplicateValue } from '@/utils/util'
  import JDate from '@/components/jeecg/JDate'  
  
  export default {
    name: "BjGwbdModal",
    components: { 
      JDate,
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title:"操作",
        width:800,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/bj/bjGwbd/add",
          edit: "/bj/bjGwbd/edit",
        }
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'name','danwei','ruzhidt','oldbm','oldzw','oldmain','oldbasic','newbm','newgw','newmain','newjbgz','jiaotongbutie','tongxunfei','shbt','fangbu','gljt','gwgz','fdgz','yldaijiao','yldaijiaoje','shiyedaijiao','shiyedaijiaoje','yiliaodaijiao','yiliaodaijiaoje','bgyuanyin','sxdt','createBy','createTime','updateBy','updateTime'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            console.log("表单提交数据",formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }
         
        })
      },
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'name','danwei','ruzhidt','oldbm','oldzw','oldmain','oldbasic','newbm','newgw','newmain','newjbgz','jiaotongbutie','tongxunfei','shbt','fangbu','gljt','gwgz','fdgz','yldaijiao','yldaijiaoje','shiyedaijiao','shiyedaijiaoje','yiliaodaijiao','yiliaodaijiaoje','bgyuanyin','sxdt','createBy','createTime','updateBy','updateTime'))
      }
      
    }
  }
</script>

<style lang="less" scoped>
/** Button按钮间距 */
  .ant-btn {
    margin-left: 30px;
    margin-bottom: 30px;
    float: right;
  }
</style>